package de.dhbw.tinf11b.vfb.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.junit.Test;

import de.dhbw.tinf11b.vfb.Curriculum;
import de.dhbw.tinf11b.vfb.CurriculumManager;
import de.dhbw.tinf11b.vfb.DegreeType;
import de.dhbw.tinf11b.vfb.Examination;
import de.dhbw.tinf11b.vfb.Module;
import de.dhbw.tinf11b.vfb.Unit;
import de.dhbw.tinf11b.vfb.exceptions.CurriculumNotFoundException;
import de.dhbw.tinf11b.vfb.exceptions.UnitNotFoundException;
import de.dhbw.tinf11b.vfb.exceptions.WeightingsMismatchException;

public class CurriculumManagerTest {

	@Test
	public void testCurriculum() throws WeightingsMismatchException, CurriculumNotFoundException, UnitNotFoundException {
		
		CurriculumManager curriculumManager = CurriculumManager.getInstance();
		
		Examination e1;
		HashMap<Examination, Integer> examinations;
		Unit u1, u2;
		Module m;
		List<Module> modules = new LinkedList<Module>();
		HashMap<Unit, Float> units;
		
		
		// we test two modules representatively, they have 8 and 5 credits, 13 in sum
		
		// MATHEMATIK I
		e1 = new Examination(true, 90);
		examinations = new HashMap<Examination, Integer>();
		examinations.put(e1, 1);
		u1 = new Unit("Lineare Algebra", examinations);
		
		e1 = new Examination(true, 90);
		examinations = new HashMap<Examination, Integer>();
		examinations.put(e1, 1);
		u2 = new Unit ("Analysis", examinations);
		
		units = new HashMap<Unit, Float>();
		units.put(u1, (float) 0.5);
		units.put(u2, (float) 0.5);
		m = new Module("Mathematik I", units, 1, 8, 96, 144);
		modules.add(m);
		
		// THEORETISCHE INFORMATIK I
		e1 = new Examination(true, 90);
		examinations = new HashMap<Examination, Integer>();
		examinations.put(e1, 1);
		u1 = new Unit("Grundlagen und Logik", examinations);
		
		units = new HashMap<Unit, Float>();
		units.put(u1, (float) 1.0);
		m = new Module("Theoretische Informatik I", units, 1, 5, 60, 90);
		modules.add(m);
		
		curriculumManager.addCurriculum("Angewandte Informatik Stand 2011", DegreeType.BACHELOR_OF_SCIENCE, modules);
		
		
		Curriculum curriculum = curriculumManager.getCurriculum("Angewandte Informatik Stand 2011");
		assertEquals(curriculum.getModules().get(0).getName(), "Mathematik I");
		assertEquals(curriculum.getProgramName(), "Angewandte Informatik Stand 2011");
		assertEquals(curriculum.getDegreeType(), DegreeType.BACHELOR_OF_SCIENCE);
		assertTrue(curriculum.getModules().get(0).getUnits().get(curriculum.getUnitByName("Lineare Algebra")) == (float) 0.5);
		assertTrue(curriculum.getModules().get(0).getUnits().get(curriculum.getUnitByName("Analysis")) == (float) 0.5);
		assertTrue(curriculum.getModules().get(1).getUnits().get(curriculum.getUnitByName("Grundlagen und Logik")) == (float) 1.0);
		
	}

}
